﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
using System.Runtime.Serialization;
using System.Text;

namespace PPFinance.Common
{
    public class JsonHelper
    {
        public static string Serialize<T>(T obj)
        {
            MemoryStream ms = new MemoryStream();
            DataContractSerializer ser = new DataContractSerializer(obj.GetType());
            ser.WriteObject(ms, obj);
            byte[] array = ms.ToArray();
            ms.Close();
            return Encoding.UTF8.GetString(array, 0, array.Length);
        }
        public static T Deserialize<T>(string jsonString)
        {
            DataContractSerializer ser2 = new DataContractSerializer(typeof(T));
            MemoryStream ms2 = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
            T obj = (T)ser2.ReadObject(ms2);
            return obj;

        }

    }

}
